package br.com.queroprestador.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Logger;


public class HttpConnector {
	
	private static final Logger log = Logger.getLogger(HttpConnector.class.getName());
	private String url;
	
	public HttpConnector(String url){
		this.url = url;
	}
	
	public String request(String param){
		
		String response = "";
		String address = String.format("%s%s", this.url, param);
		
		try {
            URL url = new URL(address);
            BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
            String line;

            while ((line = reader.readLine()) != null) {
                response = response+line;
            }
            reader.close();

        } catch (MalformedURLException e) {
           log.severe(e.getMessage());
        } catch (IOException e) {
        	log.severe(e.getMessage());
        }
		
	return response;
	}
	

}
